package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.entity.AppSearchT;
import com.panshi.service.impl.AppSearchTServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 搜索表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-21
 */
@RestController
public class AppSearchTController {

    @Autowired
    private AppSearchTServiceImpl appSearchTService;

    @ApiOperation("分页搜索 模糊查询")
    @GetMapping("/app-search-t/searchPage/{page}/{limit}/{title}")
    public List<AppSearchT> searchPage(@PathVariable int page,@PathVariable int limit,@PathVariable String title){
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<AppSearchT> pageParam = new Page<>(page, limit);

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("search_title",title);
        wrapper.orderByDesc("read_count");
        appSearchTService.page(pageParam,wrapper);
        return pageParam.getRecords();
    }

    @ApiOperation("分页搜索")
    @GetMapping("/app-search-t/searchNew/{page}/{limit}")
    public List<AppSearchT> searchNew(@PathVariable int page,@PathVariable int limit){
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<AppSearchT> pageParam = new Page<>(page, limit);

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.orderByDesc("read_count");
        appSearchTService.page(pageParam,wrapper);
        return pageParam.getRecords();
    }


    @ApiOperation("查询搜索数")
    @GetMapping("/app-search-t/searchCount/{title}")
    public Integer searchCount(@PathVariable String title){
        return appSearchTService.count(new QueryWrapper<AppSearchT>().like("search_title",title));
    }

}

